var $,
    layer,
    form,
    table;
layui.use(['jquery', 'table', 'layer', 'form'], function () {
    var $ = layui.jquery,
        layer = layui.layer,
        form = layui.form,
        table = layui.table;
});

getTableData();
function getTableData(executionTime, operationType, updateId) {
    $.ajax({
        url:'/Product/getProductOperationLogs',
        dataType: 'json',
        data: {
            'type' : 2,
            'executionTime' : executionTime,
            'operationType' : operationType,
            'updateId' : updateId,
        },
        success: function (item) {
            getTable(item.data);
        }
    });
};

function getTable(data) {

    layui.use(['table'], function () {
            table = layui.table;

        table.render({
            elem: '#demo',
            data: data,
            page:true,
            limit:10,
            text: {
                none: '暂无相关数据' //默认：无数据。
            },
            cols:[[
                {checkbox:true},
                {align: 'center', title: '序号', templet: function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:'trueName',title:'管理员名称',align:'center',height:'20px'},
                {field:'operationList', title: '操作列表', align:'center'},
                {field:'executionTime',title:'执行时间',align:'center'},
                {title:'操作类型',align:'center',templet:function(data){
                        if(data.operationType === 1){
                            return"添加";
                        }else if(data.operationType === 2){
                            return "编辑";
                        }else if(data.operationType === 3){
                            return "查看";
                        }else if(data.operationType === 4){
                            return "删除";
                        }else{
                            return "无内容";
                        }
                    }},
                {field:'remarks',title:'备注',align:'center'},
                {field:'', title:'操作',align:'center', templet:function (data) {
                        return '<a class="operation" onclick="delOperation('+data.id+')">删除</a>'
                    }}
            ]]
        });
    });
};

//删除商品操作记录
function delOperation(id) {
    $.ajax({
        url: '/Product/deleteProductOperationLog',
        dataType: 'json',
        data: {
            'id': id,
        },
        success: function (item) {
            if (item.data) {
                layer.msg('删除成功');
                getTableData();
            } else {
                layer.msg('删除失败');
            }
        }
    });
};

//搜索
function selProduct () {
    layui.use(['form'], function () {
        form = layui.form;
        var val = form.val('formDemo');
        if (val.updateId != null){
            $.ajax({
                url: '/Product/getByNameId',
                dataType: 'json',
                async: false,
                data: {
                    'name': val.updateId,
                },
                success: function (item) {
                    if (item.data.length == 1) {
                        val.updateId = item.data[0];
                    }
                }
            });
        }
        getTableData(val.executionTime, val.operationType, val.updateId);
    });
}

//刷新
function refresh () {
    location.reload();
}

//返回首页
function backOff(){
    parent.jumpSystemHome();
}
